% 有两个参考系，S1和S2，S2相对于S1以速度b向右运动
% S1中观察到的Lorentz实标量场为 u = cos(...)
% 演示在S2中的观察
% 可能有 bug
% Gitee Repo

clc
clear

L = 20;
dx = 0.1;

[x2,y2] = meshgrid(0:dx:L);
n = size(x2,1);
u_rel = zeros(n,n);
u_classical = zeros(n,n);

t2 = 0;

b = 0.6;
g = 1/sqrt(1-b^2);
Lorentz = [g,g*b,0,0;g*b,g,0,0;0,0,1,0;0,0,0,1];

T = 3;
v = 1;
theta = 0;
w = 2*pi/T;k = w/v;kx = k*cosd(theta);ky = k*sind(theta);
u_func = @(x,y,t) cos(w*t - kx*x - ky*y);

figure
clf
hold on
axis equal
axis ([0,L,0,L,-5,5])
h_rel = surf(x2,y2,u_rel,'EdgeColor','None');
h_classcial = mesh(x2,y2,u_classical);
xlabel('x'); ylabel('y'); zlabel('u');legend('relativity','classical')
view(30,45)

for tick = 1:200
    t2 = 0.1*tick;

    X2 = [t2*ones(1,n*n);x2(:)';y2(:)';zeros(1,n*n)];
    _X1 = Lorentz*X2;

    _t1 = reshape(_X1(1,:),n,n);
    _x1 = reshape(_X1(2,:),n,n);
    _y1 = reshape(_X1(3,:),n,n);

    u_rel = u_func(_x1,_y1,_t1);
    u_classical = u_func(x2+b*t2,y2,t2);

    set(h_rel,'ZData',u_rel);
    set(h_rel,'CData',u_rel);
    set(h_classcial,'ZData',u_classical);

##    if(abs(u_rel(1,1)) < 0.1 )
##        disp(t2)
##    end
    drawnow
    pause(0.1)
end

